<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>系统配置管理</title>
<script type="text/javascript" src="${ctx}/jeasyui-extensions/jeasyui-extensions/jquery-easyui-euploadify/jquery.euploadify.js"></script>
<script type="text/javascript">
	var $grid;
	var state = "";
	$(function() {
		$grid = $("#grid").datagrid($.extend(datagridOption, {
			url : "${ctx}/wx/media/dataGrid",
			columns : [ [ {
				field : 'ck',
				checkbox : true
			}, {
				field : 'mediaType',
				title : '媒体类型',
				sortable : true
			}, {
				field : 'title',
				title : '标题',
				sortable : true
			}, {
				field : 'introduction',
				title : '描述',
				sortable : true
			}, {
				field : 'fileName',
				title : '附件名称',
				sortable : true
			}, {
				field : 'filePath',
				title : '保存路径',
				sortable : true
			}, {
				field : 'fileSize',
				title : '附件大小',
				sortable : true
			}, {
				field : 'uploadTime',
				title : '上传时间',
				sortable : true
			}, {
				field : 'lastDownloadTime',
				title : '最后下载时间',
				sortable : true
			}, {
				field : 'fileType',
				title : '文件类型',
				sortable : true
			}, {
				field : 'uploader',
				title : '上传者',
				sortable : true
			} ] ]
		}));

		$grid.datagrid('enableFilter', [ buildDGFilterYesOrNoFieldOptions($grid, 'enable') ]);

		fn_initComboNotId("mediaType", "mediaType", true);//媒体类型
		fn_initComboNotId("fileType", "fileType", false);//文件类型

		$("#add").click(function() {
			$("#fm").form("clear");
			$('#fm').form('load');
			state = "";
			$("#dlg").dialog("open").dialog("setTitle", "新增微信多媒体");
		});
		$("#edit").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (!rowData) {
				showInfo("您未选中行，无法编辑");
			} else {
				$("#dlg").dialog("open").dialog("setTitle", "编辑微信多媒体");
				state = "";
				$("#fm").form("clear");
				$("#fm").form("load", rowData);
				//fn_setValueForComboBox("mediaType", rowData.mediaType, rowData.mediaType);
				$("#mediaType").combox('setValue',rowData.mediaType);
				fn_setValueForComboBox("fileType", rowData.fileType, rowData.fileType);
			}
		});
		$("#delete").click(function() {
			multiDeleteDataGrid($grid, "${ctx}/wx/media/multiDelete");
		});

		$("#excelExport").click(function() {
			var url = "${ctx}/wx/media/excelExport?" + $.param($grid.datagrid('options').queryParams);
			if ($grid.datagrid("options").filterRules) {
				url += "&filterRules=" + JSON.stringify($grid.datagrid("options").filterRules);
			}
			window.parent.location.href = url;
		});
		
		$("#thumbMedia").euploadify({
			multiTemplate : 'simple',
			multi : true,
			auto : false,
			showStop : true,
			showCancel : true,
			width : 402,
			//'fileTypeExts' : '*.mp3,*.mp4',
			'queueSizeLimit' : 1,// 上传队列中所允许的文件数量
			'simUploadLimit' : 1,// 允许同时上传的文件数量
			swf : '${ctx }/static/uploadify/uploadify.swf?var=' + (new Date()).getTime(),
			uploader : '${ctx }/basic/basicFile/upload',
			onUploadSuccess : function(file, data, response) {
				var obj = eval('(' + data + ')');
				$("#thumbMediaId").val(obj.obj.id);
				$("#fileName").val(obj.obj.fileName);
				$("#filePath").val(obj.obj.filePath);
				$("#fileSize").val(obj.obj.fileSize);
				$("#uploadTime").val(obj.obj.uploadTime);
				//$("#fileType").val(obj.obj.fileType);
				fn_setValueForComboBox("fileType", obj.obj.fileType, obj.obj.fileType);
				$("#uploader").val(obj.obj.createBy);
			}
		});
	});
	
	function fn_save() {
		state = "submit";
		$("#fm").form("submit", {
			url : "${ctx}/wx/media/update",
			success : function(data) {
				if (data.success) {
					$("#thumbMedia").euploadify("cancel", "*");
					$("#dlg").dialog('close');
					$("#grid").datagrid("load").datagrid("clearSelections").datagrid("clearChecked");
				}
				showInfo(data.msg);
			}
		});
	}
	function fn_cancel() {
		state = "cancel";
		$("#thumbMedia").euploadify("cancel", "*");
		$('#dlg').dialog('close');
	}
	
	function dorpFileForServer() {
		var id = $("input[title='uploadify']").attr("id");
		var deleteId = id + "Id";
		if (state == "") {
			if ($("#last" + deleteId).val() != $("#" + deleteId).val()) {
				$.post("${ctx}/basic/basicFile/multiDelete", {
					ids : $("#" + deleteId).val()
				}, function(data) {
					$("#" + deleteId).val("");
				}, "json");
			}
		} else if (state == "cancel") {
			if ($("#" + deleteId).val() != "" && $("#" + deleteId).val() != $("#last" + deleteId).val()) {
				$.post("${ctx}/basic/basicFile/multiDelete", {
					ids : $("#" + deleteId).val()
				}, function(data) {
					$("#" + deleteId).val("");
				}, "json");
			}
		} else if (state == "submit") {
			if ($("#last" + deleteId).val() != "" && $("#last" + deleteId).val() != $("#" + deleteId).val()) {
				$.post("${ctx}/basic/basicFile/multiDelete", {
					ids : $("#last" + deleteId).val()
				}, function(data) {
					$("#last" + deleteId).val("");
				}, "json");
			}
		}
		state = "";
	}
	
</script>
</head>

<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
	</div>
	<div id="tt" class="easyui-toolbar">
		<shiro:hasPermission name="media:update">
			<a id="add" class="easyui-linkbutton" data-options="plain: true, iconCls: 'icon-standard-add'">新增</a>
			<a id="edit" class="easyui-linkbutton" data-options="plain: true, iconCls: 'icon-hamburg-pencil'">编辑</a>
		</shiro:hasPermission>
		<shiro:hasPermission name="media:delete">
			<a id="delete" class="easyui-linkbutton" data-options="plain: true, iconCls: 'icon-hamburg-busy'">删除</a>
			<div class="dialog-tool-separator"></div>
		</shiro:hasPermission>
		<shiro:hasPermission name="media:export">
			<a id="excelExport" class="easyui-linkbutton" data-options="plain: true, iconCls: 'icon-standard-page-excel'">Excel导出</a>
		</shiro:hasPermission>
	</div>
	<shiro:hasPermission name="media:update">
		<div id="dlg" class="easyui-dialog" style="width: 610px; height: 280px; padding: 10px 20px"
			data-options="iconCls:'icon-save',resizable:true,modal:true, buttons:[
                    { text: '保存', iconCls: 'icon-ok', handler: function () { fn_save(); } },
                    { text: '取消', iconCls:'icon-cancel', handler: function () { fn_cancel(); } }
                ],closed:true">
			<form id="fm" method="post">
				<input type="hidden" name="id" />
				<table id="tbl">
					<tr>
						<td><label>媒体类型:</label></td>
						<td><input id="mediaType" name="mediaType"></td>
						<td><label>标题:</label></td>
						<td><input name="title" class="easyui-validatebox" data-options="required: true"></td>
					</tr>
					<tr>
						<td>媒体文件：</td>
						<td height="50px" width="260px" colspan="3"><input id="thumbMedia" name="thumbMedia" type="text" title="uploadify" /><input id="thumbMediaId"
							name="thumbMediaId" type="hidden" onchange="tupianisChange()" /></td>
					</tr>
					<tr>
						<td><label>描述:</label></td>
						<td><input name="introduction" class="easyui-validatebox"></td>
						<td><label>附件名称:</label></td>
						<td><input id="fileName" name="fileName" readonly="readonly" class="easyui-validatebox"></td>
					</tr>
					<tr>
						<td><label>保存路径:</label></td>
						<td><input id="filePath" name="filePath" readonly="readonly" class="easyui-validatebox"></td>
						<td><label>附件大小:</label></td>
						<td><input id="fileSize" name="fileSize" readonly="readonly" class="easyui-validatebox"></td>
					</tr>
					<tr>
						<td><label>上传时间:</label></td>
						<td><input id="uploadTime" name="uploadTime" readonly="readonly" class="easyui-validatebox"></td>
						<td><label>最后下载时间:</label></td>
						<td><input id="lastDownloadTime" name="lastDownloadTime" readonly="readonly" class="easyui-validatebox"></td>
					</tr>
					<tr>
						<td><label>文件类型:</label></td>
						<td><input id="fileType" name="fileType" readonly="readonly" id="fileType"></td>
						<td><label>上传者:</label></td>
						<td><input id="uploader" name="uploader" readonly="readonly" class="easyui-validatebox"></td>
					</tr>
				</table>

			</form>
		</div>
	</shiro:hasPermission>
</body>
</html>
